package com.xiguaji.tiktok.config;

import com.xiguaji.tiktok.config.interceptor.MyTikTokersInterceptor;
import com.xiguaji.tiktok.config.interceptor.TokenInterceptor;
import com.xiguaji.tiktok.config.interceptor.UserVisitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    TokenInterceptor tokenInterceptor;

    @Autowired
    MyTikTokersInterceptor myTikTokersInterceptor;

    @Autowired
    UserVisitInterceptor userOperationInterceptor;

    @Value("${sitemap.path}")
    String sitemapPath;
    // java -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=5005 -jar tiktok-0.0.1-SNAPSHOT.jar
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userOperationInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html/**","/swagger-resources/**","/webjars/**","/error/**","/static/**","/sitemap.xml","/sitemap.html","/sitemap.txt","/sitemap.xsl","/sitemap.xml.gz","/robots.txt");

        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").
                excludePathPatterns("/v1/testPage","/v1/register","/v1/send/code","/v1/set/auth",
                        "/v1/token/*","/v1/verify/subuser","/help-art/**","/tiktoker/**","/tiktok/**","/help-arts/**","/help/**","/video/**","/influencer/**","/influencerDetail/**",
                        "/v1/validate/email/register", "/v1/validate/email","/v1/count/visit/register","/v1/config",
                        "/v1/user/rest/pwd","/v1/login","/v1/google/login","/pricing","/v1/login/out",
                        "/v1/order/callback","/v1/guoji/pay/callback","/swagger-resources/**","/ranking/**","/v1/ranking/**","/v1/common/**",
                        "/webjars/**", "/v2/**","/v1/blogger/type","/instagram/**","/ins/dic/**","/ins/product/search","/ins/brand/rank/dates",
                        "/defaultImage/**",
                        "/swagger-ui.html/**","/order","/instagram/favorite",
                        "/","/policy","/v1/fb/login","/ins/search","/ins/blogger","/ins/blogger/search","/ins/media/search","/ins/brand/search",
                        "/error/**","/static/**","/ins/fg/update","/ins/fg/date","/v1/sys/visit/record",
                        "/ins/adec/update","/ins/adec/date","/ins/product/rank/dates","/v1/login/out",
                        "/sitemap.xml","/sitemap.html","/sitemap.txt","/sitemap.xsl","/sitemap.xml.gz","/robots.txt");
        registry.addInterceptor(myTikTokersInterceptor).addPathPatterns("/v1/my/tiktok/**");

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/sitemap*")
                .addResourceLocations("file:///"+sitemapPath+"/");
        registry.addResourceHandler("/robots*")
                .addResourceLocations("file:///"+sitemapPath+"/");
//        System.out.println("file:///"+sitemapPath+"/");
    }


}
